'use strict';
const gulp = require("gulp");
const minify = require('gulp-minify');
const ts = require('gulp-typescript');
const tsProject = ts.createProject('tsconfig.json');
const inject = require('gulp-inject-string');

const name = "apeng"
/**版本code 只能递增 */
const versionCode = 1

const outDir = './bin/' + versionCode

gulp.task('buildJs', () => {
    return tsProject.src()
        .pipe(tsProject())
        .js.pipe(inject.replace(["var ", name, ";"].join(""), ''))
        .pipe(inject.prepend(["window.", name, " = {versionCode:", versionCode, "};\n"].join("")))
        .pipe(inject.replace('var __extends', 'window.__extends'))
        .pipe(minify({ ext: { min: ".min.js" } }))
        .pipe(gulp.dest(outDir));
})

gulp.task("buildDts", () => {
    return tsProject.src()
        .pipe(tsProject())
        .dts.pipe(inject.append('/**说明文档*/'))
        .pipe(gulp.dest(outDir));
});

gulp.task("copy", () => {
    return gulp.src('bin/'+versionCode+'/apeng.js')
        .pipe(gulp.dest('./../FairyGUI-dom-main/test/build'))
});

// gulp.task("copyDts", () => {
//     return gulp.src('bin/pe.d.ts')
//         // .pipe(gulp.dest('/Users/hooper/base/project/NewProject_1'))
// });

gulp.task('build', gulp.series(
    gulp.parallel('buildJs'),
    gulp.parallel('buildDts'),
    gulp.parallel('copy'),
    // gulp.parallel('copyDts'),
)
)